<template>
  <div class="app-container">
    <div class="item2">
      <div class="header">
        <div class="title1">
          <i class="el-icon-data-analysis"></i><span>每日工作量统计</span>
        </div>
        <div class="backB">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
        </div>
      </div>
      <div class="formCenter">
        <el-form
          :model="queryParams"
          size="large"
          :inline="true"
          ref="queryForm"
          :rules="queryRules"
          label-width="90px"
        >
          <el-form-item label="工号:" prop="userId">
            <el-input
              v-model="queryParams.userId"
              placeholder="请输入工号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="工作类型:" prop="workType">
            <el-select
              v-model="queryParams.workType"
              placeholder="请选择工作类型"
              clearable
            >
              <el-option
                v-for="dict in dict.type.daywork_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="角色:" prop="userJs">
            <el-select
              v-model="queryParams.userJs"
              placeholder="请选择角色"
              clearable
            >
              <el-option
                v-for="item in rolelist"
                :key="item.roleid"
                :label="item.roledescr"
                :value="item.roledescr"
              />
            </el-select>
          </el-form-item> -->
          <el-form-item label="日期:" prop="addTime">
            <el-date-picker
              v-model="addTime"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <!-- <el-form-item label="日期:" prop="userRq">
            <el-date-picker
              v-model="queryParams.userRq"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
            >
            </el-date-picker>
          </el-form-item> -->
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="medium"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="medium"
              @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <div class="exportstyle">
          <el-button
            type="primary"
            plain
            icon="el-icon-download"
            size="medium"
            class="exportBtn"
            @click="handleExport"
            >导出</el-button
          >
        </div>
      </div>
      <div class="tableBox">
        <el-table
          :data="tableData"
          border
          height="680"
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
        >
          <!-- <el-table-column align="center" prop="wlType" label="物流类型">
        </el-table-column> -->
          <!-- <el-table-column align="center" prop="seqId" label="序号">
          </el-table-column> -->
          <!-- <el-table-column align="center" prop="userRq" label="日期">
          </el-table-column> -->
          <el-table-column align="center" prop="userJs" label="角色">
          </el-table-column>
          <el-table-column align="center" prop="userId" label="人员ID">
          </el-table-column>
          <el-table-column align="center" prop="userName" label="人员名称">
          </el-table-column>
          <el-table-column align="center" prop="userTm" label="条目数">
          </el-table-column>
          <el-table-column align="center" prop="userBz" label="备注">
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-document"
                @click="handleDetails(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <!-- <div class="totalBox">
          总条目数
          <div class="workBox">{{ workCount }}</div>
        </div> -->
      </div>

      <div>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="handleQuery"
        />
      </div>
      <el-dialog
        :title="availabletitle"
        :visible.sync="availableDialog"
        :close-on-click-modal="false"
      >
        <el-table
          :data="detailtableData"
          border
          height="680"
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
        >
          <!-- <el-table-column align="center" prop="wlType" label="物流类型">
        </el-table-column> -->
          <!-- <el-table-column align="center" prop="seqId" label="序号">
          </el-table-column> -->
          <el-table-column align="center" prop="userRq" label="日期">
          </el-table-column>
          <el-table-column align="center" prop="userJs" label="角色">
          </el-table-column>
          <el-table-column align="center" prop="userId" label="人员ID">
          </el-table-column>
          <el-table-column align="center" prop="userName" label="人员名称">
          </el-table-column>
          <el-table-column align="center" prop="userTm" label="条目数">
          </el-table-column>
          <el-table-column align="center" prop="userBz" label="备注">
          </el-table-column>
        </el-table>
        <div>
          <pagination
            v-show="detailtotal > 0"
            :total="detailtotal"
            :page.sync="detailParams.pageNum"
            :limit.sync="detailParams.pageSize"
            @pagination="detaillist"
          />
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { workstaticlist, roleslist } from "@/api/subSystem/continer";
import { listDaywork, listDayworktotal } from "@/api/subSystem/workday";
export default {
  dicts: ["user_bz", "daywork_type"],
  data() {
    return {
      // 详情弹窗
      availabletitle: "详情查看",
      availableDialog: false,
      // 总条数
      total: 0,
      detailtotal: 0,
      addTime: [
        // new Date().toISOString().split("T")[0],
        // new Date().toISOString().split("T")[0],
      ],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: "",
        workType: "",
        userRq: "",
        // userJs: "",
      },
      detailParams: {
        pageNum: 1,
        pageSize: 10,
        userId: "",
        workType:"",
      },
      tableData: [],
      detailtableData: [],
      loading: false,
      queryRules: {
        // userName: [
        //   { required: true, message: "请输入用户名称", trigger: "blur" },
        // ],
      },
      rolelist: [],
      workCount: null,
    };
  },
  mounted() {
    // this.handleQuery();
    this.Roleslist();
  },
  methods: {
    // 详情
    handleDetails(row) {
      this.availableDialog = true;
      this.detailParams.params = {};
      this.detailParams.params["beginTime"] = this.addTime[0];
      this.detailParams.params["endTime"] = this.addTime[1];
      // this.$set(this.detailParams, "userId", row.userId);
      this.detailParams.userId = row.userId;
      this.detailParams.workType = row.workType;
      this.detaillist();
    },
    detaillist() {
      listDaywork(this.detailParams).then((res) => {
        this.detailtableData = res.rows;
        this.detailtotal = res.total;
        this.loading = false;
      });
    },
    Roleslist() {
      roleslist().then((res) => {
        console.log(res);
        this.rolelist = res.data;
      });
    },
    goBack() {
      this.$router.push("/subSystem1");
    },
    handleQuery() {
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          this.queryParams.params = {};
          if (null != this.addTime && "" != this.addTime) {
            this.queryParams.params["beginTime"] = this.addTime[0];
            this.queryParams.params["endTime"] = this.addTime[1];
          }
          console.log(this.queryParams);
          if (
            this.queryParams.params["beginTime"] &&
            this.queryParams.params["endTime"]
          ) {
            this.loading = true;
            // listDaywork(this.queryParams).then((res) => {
            //   this.tableData = res.rows;
            //   this.total = res.total;
            //   this.loading = false;
            // });
            listDayworktotal(this.queryParams).then((res) => {
              this.tableData = res.rows;
              this.total = res.total;
              this.loading = false;
            });
          } else {
            this.loading = false;
            this.$message.error("请先选择日期");
          }
          // this.queryParams.params = {};
          // if (null != this.addTime && "" != this.addTime) {
          //   this.queryParams.params["beginTime"] = this.addTime[0];
          //   this.queryParams.params["endTime"] = this.addTime[1];
          // }
          // workstaticlist(this.queryParams).then((res) => {
          //   this.tableData = res.data.dayList;
          //   // this.total = res.total;
          //   this.workCount = res.data.workCount;
          //   this.loading = false;
          // });
          // if (this.addTime.length > 0) {
          //   listDaywork(this.addDateRange(this.queryParams, this.addTime)).then(
          //     (res) => {
          //       this.tableData = res.rows;
          //       this.total = res.total;
          //       this.loading = false;
          //     }
          //   );
          // }else{
          //   this.loading = false;
          //   this.$message.error("请先选择时间");
          // }
        }
      });
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.addTime = [];
      // this.queryParams.workType = "";
    },
    handleExport() {
      // this.download(
      //   "system/daywork/export",
      //   {
      //     ...this.queryParams,
      //   },
      //   `post_${new Date().getTime()}.xlsx`
      // );
      this.download(
        "system/dayworkapart/export",
        {
          ...this.queryParams,
        },
        `工作量统计_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .el-icon-data-analysis::before {
    color: #00d9ff;
    margin-right: 8px;
  }
  .title1 {
    font-size: 16px;
    // margin-bottom: 15px;
    color: #808080;
    width: 200px;
    padding: 5px;
    border-bottom: 1px dotted #8ddfff;
  }
  .header {
    margin-top: -10px;
    margin-bottom: 20px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-date-editor.el-input,
    .el-date-editor.el-input__inner {
      width: 220px;
      margin-right: 20px;
    }

    .backB {
      cursor: pointer;

      img {
        width: 20%;
      }
    }
  }
  .formCenter {
    width: 100%;
    // height: 62px;
    display: flex;
    // justify-content: space-between;
    justify-content: center;
    align-items: center;
  }
  .tableBox {
    display: flex;
    justify-content: space-around;
    // .totalBox {
    //   width: 16%;
    //   height: 680px;
    //   display: flex;
    //   flex-direction: column;
    //   // justify-content: center;
    //   align-items: center;
    //   font-size: 50px;
    //   font-weight: 700;
    //   color: rgb(255, 72, 0);
    //   .workBox {
    //     font-size: 70px;
    //     margin-top: 70px;
    //     color: rgb(0, 255, 13);
    //   }
    // }
  }
  .footer {
    margin-top: 20px;
    width: 100%;
    min-height: 200px;
  }
  .el-select {
    width: 240px;
  }
  ::v-deep .el-form {
    margin-left: 2%;
  }
  .exportstyle {
    height: 62px;
    // margin-right: 5%;
    margin-left: 10%;
  }
}
</style>